package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Activity.PopUpWindowFragment.Discuss.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Activity.PopUpWindowFragment.Discuss.ItemBean.Discuss;
import com.example.tnot.Util.ToastUtil;

import org.w3c.dom.Text;

import java.util.List;

public class rvDiscussAdapter extends RecyclerView.Adapter<rvDiscussAdapter.ViewHolder>{
    private List<Discuss> DiscussList;
    public rvDiscussAdapter(List<Discuss> DiscussList){
        this.DiscussList = DiscussList;
    }
    @NonNull
    @Override
    public rvDiscussAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_discuss,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull rvDiscussAdapter.ViewHolder holder, int position) {
        holder.iv_icon.setImageResource(DiscussList.get(position).getIcon());
        holder.tv_teacher.setText(DiscussList.get(position).getTeacherName());
        holder.tv_type.setText(DiscussList.get(position).getTv_type());
        holder.tv_time.setText(DiscussList.get(position).getTime());
        holder.tv_discussName.setText(DiscussList.get(position).getDiscussName());
        holder.tv_discussContent.setText(DiscussList.get(position).getDiscussContent());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_disscussHomeFragment_to_discussDetailFragment);
            }
        });
    }

    @Override
    public int getItemCount() {
        return DiscussList.size();
    }
    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_icon,iv_like,iv_comment;
        TextView tv_teacher,tv_type,tv_time,tv_discussName,tv_discussContent;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_icon = itemView.findViewById(R.id.iv_icon);
            iv_like = itemView.findViewById(R.id.iv_like);
            iv_comment = itemView.findViewById(R.id.iv_comment);
            tv_teacher = itemView.findViewById(R.id.tv_teacher);
            tv_type = itemView.findViewById(R.id.tv_type);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv_discussName = itemView.findViewById(R.id.tv_discussName);
            tv_discussContent = itemView.findViewById(R.id.tv_discussContent);
        }
    }
}
